package com.locationtracker.plus.app

import com.kingja.loadsir.callback.SuccessCallback
import com.kingja.loadsir.core.LoadSir
import com.locationtracker.plus.BuildConfig
import com.locationtracker.plus.app.event.AppViewModel
import com.locationtracker.plus.app.event.EventViewModel
import com.locationtracker.plus.app.weight.loadCallBack.EmptyCallback
import com.locationtracker.plus.app.weight.loadCallBack.ErrorCallback
import com.locationtracker.plus.app.weight.loadCallBack.LoadingCallback
import com.tencent.bugly.crashreport.CrashReport
import com.tencent.mmkv.MMKV
import me.hgj.jetpackmvvm.base.BaseApp
import me.hgj.jetpackmvvm.ext.util.jetpackMvvmLog
import me.jessyan.retrofiturlmanager.RetrofitUrlManager

/**
 * 作者　: hegaojian
 * 时间　: 2019/12/23
 * 描述　:
 */

//Application全局的ViewModel，里面存放了一些账户信息，基本配置信息等
val appViewModel: AppViewModel by lazy { App.appViewModelInstance }

//Application全局的ViewModel，用于发送全局通知操作
val eventViewModel: EventViewModel by lazy { App.eventViewModelInstance }

open class App : BaseApp() {

    companion object {
        lateinit var instance: App
        lateinit var eventViewModelInstance: EventViewModel
        lateinit var appViewModelInstance: AppViewModel
    }

    override fun onCreate() {
        super.onCreate()
        MMKV.initialize(this.filesDir.absolutePath + "/mmkv")
        CrashReport.initCrashReport(this, "4e05be7684", false)
        RetrofitUrlManager.getInstance().putDomain("EventDomain", "http://locationtp.snpsmar.cn")
        RetrofitUrlManager.getInstance().putDomain("GoogleMapDomain", "https://maps.googleapis.com/maps/api")

        instance = this
        eventViewModelInstance = getAppViewModelProvider().get(EventViewModel::class.java)
        appViewModelInstance = getAppViewModelProvider().get(AppViewModel::class.java)
        //界面加载管理 初始化
        LoadSir.beginBuilder()
            .addCallback(LoadingCallback())//加载
            .addCallback(ErrorCallback())//错误
            .addCallback(EmptyCallback())//空
            .setDefaultCallback(SuccessCallback::class.java)//设置默认加载状态页
            .commit()
        jetpackMvvmLog = BuildConfig.DEBUG
    }
}
